﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using KaraokeManagementDTO;
using KaraokeManagementBUS;

namespace KaraokeManagement
{
    public partial class ucQuanLyKhachHang : UserControl
    {
        public static int staticMaKhachHang = -1;

        public ucQuanLyKhachHang()
        {
            InitializeComponent();
            
        }

        private void btnThem_Click(object sender, EventArgs e)
        {
            frmKhachHang frm = new frmKhachHang();
            frm.ShowDialog();
            loadDanhSachKhachHang();
        }

        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            frmKhachHang frm = new frmKhachHang();
            frm.ShowDialog();
            loadDanhSachKhachHang();
        }


        public void initLoaiKhachHang()
        {
            cbLoaiKhachHang.DataSource = new LoaiKhachHangBUS().layDanhSachLoaiKhachHang();
            cbLoaiKhachHang.DisplayMember = "TenLoaiKhachHang";
            cbLoaiKhachHang.ValueMember = "ID";
        }

        private void ucQuanLyKhachHang_Load(object sender, EventArgs e)
        {
            dgvDanhSachKhachHang.AutoGenerateColumns = false;
            initLoaiKhachHang();
            loadDanhSachKhachHang();
        }

        public void loadDanhSachKhachHang()
        {
            //dgvDanhSachKhachHang.Rows.Clear();
            dgvDanhSachKhachHang.DataSource = new KhachHangBUS().layDanhSachKhachHang();
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn có chắc không ?", "Karaoke ABC", MessageBoxButtons.YesNo) == DialogResult.No)
            {
                return;
            }

            if (dgvDanhSachKhachHang.Rows.Count > 0)
            {
                int MaKhachHang = int.Parse(dgvDanhSachKhachHang.SelectedRows[0].Cells["ID"].Value.ToString());
                if (new KhachHangBUS().xoaKhachHang(MaKhachHang))
                {
                    MessageBox.Show("Xóa thành công khách hàng !", "Karaoke ABC");
                }
            }
            loadDanhSachKhachHang();
        }

        private void dgvDanhSachKhachHang_SelectionChanged(object sender, EventArgs e)
        {
            if (dgvDanhSachKhachHang.SelectedRows.Count > 0)
            {
                staticMaKhachHang = int.Parse(dgvDanhSachKhachHang.SelectedRows[0].Cells["ID"].Value.ToString());
            }
        }

        
    }
}
